package edu.ynu.se.xiecheng.achitectureclass.nongye.controller;

import edu.ynu.se.xiecheng.achitectureclass.nongye.dao.DeviceDAO;
import edu.ynu.se.xiecheng.achitectureclass.nongye.entity.Device;
import edu.ynu.se.xiecheng.achitectureclass.nongye.service.DeviceService;
import edu.ynu.se.xiecheng.achitectureclass.common.controller.LogicController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


import java.util.List;

@Api(tags = "设备管理")
@RestController
@RequestMapping("/device")
public class DeviceController extends LogicController<DeviceService, DeviceDAO, Device, String> {

    @Autowired
    public DeviceController(DeviceService deviceService) {
        super(deviceService);
    }

    @ApiOperation("根据设备ID获取设备")
    @GetMapping("/getByBoxId")
    public Device getDeviceByBoxId(@RequestParam String boxId) {
        return getService().getDeviceByBoxId(boxId);
    }

    @ApiOperation("根据大棚ID获取所有设备")
    @GetMapping("/getByGreenhouseId")
    public List<Device> getDevicesByGreenhouseId(@RequestParam String greenhouseId) {
        return getService().getDevicesByGreenhouseId(greenhouseId);
    }

    @ApiOperation("获取所有设备")
    @GetMapping("/getAlldevice")
    public List<Device> getAllDevices() {
        return getService().getAll();
    }

    @ApiOperation("创建设备")
    @PostMapping("/postdevice")
    public Device createDevice(@RequestBody Device device) {
        return getService().POST(device);
    }
}
